<?php

$typeLookup = array();
$macroLookup = array();
$displayNameLookup = array();
$currentId = 0;
function defineType($name, $displayName) {

	global $currentId, $typeLookup, $displayNameLookup;

	define($name, $currentId);

	$typeLookup[$currentId] 	= $name;
	$displayNameLookup[$currentId] 	= $displayName;

	if ($currentId == 0)
		$currentId = 1;
	else
		$currentId = $currentId << 1;
}

function defineMacro($typeIds, $macroName, $macroCallback, $isMultiple=null) {

	global $macroLookup;

	if (!isset($macroLookup[$typeIds])){
		$macroLookup[$typeIds] = array();
	}

	array_push($macroLookup[$typeIds], array($macroName, $macroCallback, $isMultiple));
}

function getTypeName($id) {
	global $typeLookup;
	return $typeLookup[$id];
}

function getTypeId($name) {
	global $typeLookup;
	foreach ($typeLookup as $typeId => $typeName) {
		if ($typeName == $name) {
			return $typeId;
		}
	}
}



function applyMacro($typeId, $macroName) {
	global $macroLookup;
	foreach ($macroLookup as $typeIds => $arr) {
		if ($typeIds & $typeId) {
			$mName = $arr[0][0];
			if ($mName == $macroName) {
				return call_user_func($arr[0][1]);
			}
		}
	}
}




defineType('SELECT_SINGLE', '');	//Needs to be 0
defineType('SELECT_MULTIPLE', '');	//Needs to be 1

defineType('TYPE_INT', 'Integer');
defineType('TYPE_FLOAT', 'Float');
defineType('TYPE_STRING', 'String');
defineType('TYPE_DATE', 'Date');
defineType('TYPE_DATERANGE', 'Date Range');

require_once(dirname(__FILE__)."/mytypes.php");
require_once(dirname(__FILE__)."/defines.types.macrofunctions.php");
require_once(dirname(__FILE__)."/defines.types.macros.php");


?>